home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
howtod2r
/
site.cls
< prev
next >
Wrap
Text File
|
1999-02-24
|
19KB
|
688 lines
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "Site"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'CLASS -- Site -- Site.cls
'--------------------------------------------------------------------------
'<Purpose>
' Encapsulate the functions and data needed to build a site's map.
'
'--------------------------------------------------------------------------
Private strFiles() As String 'holds files for the site
Private strSmallFiles() As String 'holds small (short) file names
Private strUKFiles() As String 'Unknown files found
Private strFilters() As String 'Filters to look for
Private strFilterLen() As String 'lengths of each filter
Private Matrix() As Integer 'The adjacency matrix
Private strDirs() As String 'The directories to search
Private intFilterCt As Integer 'amt of filters
Private intUKFileCt As Integer 'amt of unknown files found
Private intFileCt As Integer 'amt of files
Private intDirCt As Integer 'amt of directories
Private strName As String 'name of this site
Private strMainDirectory As String 'main directory to start parsing
Private strID As String 'internal name for this site
Private blnChooseRoot As Boolean 'did user provide start point
Private strRoot As String 'start point for map
Private Visited() As Boolean 'Used by traversal algorithms
'*******************************************************************************
Private Function MapName(ByVal Vertex As String) As Integer
Dim i As Integer
Vertex = UCase$(Vertex)
For i = 1 To intFileCt
If strSmallFiles(i) = Vertex Then
MapName = i
Exit For
End If
Next
End Function
'*******************************************************************************
Public Sub RemoveFilter(intIndex As Integer)
Dim i As Integer
strFilters(intIndex) = strFilters(intFilterCt)
ReDim Preserve strFilters(intFilterCt - 1)
intFilterCt = intFilterCt - 1
End Sub
'*******************************************************************************
Private Sub ResetVisited()
Dim i As Integer
For i = 1 To intFileCt
Visited(i) = False
Next
End Sub
'*******************************************************************************
Public Sub SaveSite(strPath As String)
On Error GoTo SaveSite_Error
Dim i As Integer 'lcv
Dim j As Integer 'lcv
Open strPath For Output As #1
If intFileCt < 1 Then
Err.Raise vbObjectError + 1, "SaveSite", "Site not fully defined. Cannot save at this time."
End If
'write site id and name
Write #1, strID, strName
'Write the number of files
Write #1, intFileCt
'write the files and short file names
For i = 1 To intFileCt
Write #1, strFiles(i), strSmallFiles(i)
Next
'write the adjacency matrix, row by row
For i = 1 To intFileCt
For j = 1 To intFileCt
Write #1, Matrix(i, j)
Next j
Next i
'Write the number of filters
Write #1, intFilterCt
'write the filters and filter lengths
For i = 1 To intFilterCt
Write #1, strFilters(i), strFilterLen(i)
Next
'write the unknown file amt
Write #1, intUKFileCt
'write out the uk files
For i = 1 To intUKFileCt
Write #1, strUKFiles(i)
Next
'Write out number of directories
Write #1, intDirCt
'Write out the directories holding the site
For i = 1 To intDirCt
Write #1, strDirs(i)
Next
'write out the site root definition
Write #1, strMainDirectory, blnChooseRoot, strRoot
Close #1
Exit Sub
SaveSite_Error:
Close #1
Err.Raise vbObjectError + 1, "Save Site", CStr(Err.Number) & " -- " + Err.Description
End Sub
'*******************************************************************************
Public Sub OpenSite(strPath As String)
On Error GoTo OpenSite_Error
Dim i As Integer 'lcv
Dim j As Integer
Open strPath For Input As #1
Input #1, strID, strName
'input the number of files
Input #1, intFileCt
ReDim strFiles(intFileCt)
ReDim strSmallFiles(intFileCt)
ReDim Visited(intFileCt)
'input the files and short file names
For i = 1 To intFileCt
Input #1, strFiles(i), strSmallFiles(i)
Next
ReDim Matrix(intFileCt, intFileCt)
'input the adjacency matrix, row by row
For i = 1 To intFileCt
For j = 1 To intFileCt
Input #1, Matrix(i, j)
Next j
Next i
'input the number of filters
Input #1, intFilterCt
ReDim strFilters(intFilterCt)
ReDim strFilterLen(intFilterCt)
'input the filters and filter lengths
For i = 1 To intFilterCt
Input #1, strFilters(i), strFilterLen(i)
Next
'input the unknown file amt
Input #1, intUKFileCt
If intUKFileCt > 0 Then
ReDim strUKFiles(intFileCt)
'input out the uk files
For i = 1 To intUKFileCt
Input #1, strUKFiles(i)
Next
End If
'input out number of directories
Input #1, intDirCt
If intDirCt > 0 Then
ReDim strDirs(intDirCt)
'input out the directories holding the site
For i = 1 To intDirCt
Input #1, strDirs(i)
Next
End If
'input out the site root definition
Input #1, strMainDirectory, blnChooseRoot, strRoot
Close #1
Exit Sub
OpenSite_Error:
Close #1
Err.Raise vbObjectError + 1, "Open Site", CStr(Err.Number) & " -- " + Err.Description
End Sub
'*******************************************************************************
Private Function AllVisited() As Boolean
Dim i As Integer
Dim blnFlag As Boolean
blnFlag = True
For i = 1 To intFileCt
If Visited(i) = False Then
blnFlag = False
Exit For
End If
Next
AllVisited = blnFlag
End Function
'*******************************************************************************
Public Sub DrawTree(tv As TreeView)
Dim n As Node
Dim idx As Integer
Dim j As Integer
Dim intNodeIdx As Integer
Dim blnAllVisited As Boolean
blnAllVisited = False
If blnChooseRoot Then
'Supplied root
idx = MapName(strRoot)
If idx = 0 Then
Exit Sub
End If
Else
'Divine the root!
idx = DivineRoot()
If idx > 0 Then
strRoot = strSmallFiles(idx)
Else
Exit Sub
End If
End If
Call ResetVisited
Set n = tv.Nodes.Add
n.Text = strName
intNodeIdx = 1
Visited(idx) = True
Set n = tv.Nodes.Add(intNodeIdx, tvwChild)
n.Text = strRoot
Call FillBranch(tv, n, idx, n.Index)
End Sub
'*******************************************************************************
Private Sub FillBranch(tv As TreeView, n As Node, idx As Integer, intNodeIdx)
'Recursive
Dim j As Integer
For j = 1 To intFileCt
If (Matrix(idx, j) = 1) And (idx <> j) And (Not Visited(j)) Then
'We have an edge
Set n = tv.Nodes.Add(intNodeIdx, tvwChild)
n.Text = strSmallFiles(j)
Visited(j) = True
If Not AllVisited() Then
Call FillBranch(tv, n, j, n.Index)
End If
End If
Next